<template>
  {{ $store.state.user.username }}
  <el-button @click="handleLogout">退出登录</el-button>
</template>
<script setup>

import {msgBox, notify} from "~/composables/utils.js";
import store from "~/store/index.js";
import {logout} from "~/api/manager.js";
import {useRouter} from "vue-router";

const router = useRouter()

function handleLogout() {
  msgBox('确定退出登录？').then(res => {
    logout().finally(() => {
      // 清除状态及cookie
      store.dispatch('logout')
      // 跳转
      router.push('/login')
      // 提示
      notify('退出成功')
    })
  })
}
</script>